package com.eam.asset.file.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;

import com.eam.asset.file.group.AssetGroup.AssetAddGroup;
import com.eam.asset.file.vo.AssetHouse.AssetHouseAddVo;
import com.eam.asset.file.vo.AssetHouse.AssetHousePutVo;
import com.eam.asset.file.vo.AssetHouse.AssetHouseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.eam.common.annotation.Log;
import com.eam.common.core.controller.BaseController;
import com.eam.common.core.domain.AjaxResult;
import com.eam.common.enums.BusinessType;
import com.eam.asset.file.domain.AssetHouse;
import com.eam.asset.file.service.IAssetHouseService;
import com.eam.common.utils.poi.ExcelUtil;
import com.eam.common.core.page.TableDataInfo;

/**
 * 房屋资产档案Controller
 *
 * @author tzf
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/asset/house")
@Api(tags = "房屋资产控制器")
@Validated
public class AssetHouseController extends BaseController {
    private final IAssetHouseService assetHouseService;

    //构造器注入
    @Autowired
    public AssetHouseController(IAssetHouseService assetHouseService) {
        this.assetHouseService = assetHouseService;
    }

    /**
     * 查询房屋资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:house:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取资产列表")
    public TableDataInfo AssetHouseGetList(AssetHouseQueryVo assetHouse) {
        startPage();
        List<AssetHouse> list = assetHouseService.selectAssetHouseList(assetHouse);
        return getDataTable(list);
    }

    /**
     * 导出房屋资产档案列表
     */
    @PreAuthorize("@ss.hasPermi('asset:house:export')")
    @Log(title = "房屋资产档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出Excel")
    public void AssetHouseExport(HttpServletResponse response, AssetHouseQueryVo assetHouse) {
        List<AssetHouse> list = assetHouseService.selectAssetHouseList(assetHouse);
        ExcelUtil<AssetHouse> util = new ExcelUtil<AssetHouse>(AssetHouse.class);
        util.exportExcel(response, list, "房屋资产档案数据");
    }

    /**
     * 获取房屋资产档案详细信息根据资产档案ID
     */
    @PreAuthorize("@ss.hasPermi('asset:house:query')")
    @GetMapping(value = "/{houseId}")
    @ApiOperation(value = "查询房屋资产")
    public AjaxResult AssetHouseGetInfoById(@PathVariable("houseId") String houseId) {
        return success(assetHouseService.selectAssetHouseByHouseId(houseId));
    }

    /**
     * 新增房屋资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:house:add')")
    @Log(title = "房屋资产档案", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "添加房屋资产")
    public AjaxResult AssetHouseAdd(@Validated(AssetAddGroup.class) @RequestBody AssetHouseAddVo assetHouse) {
        return toAjax(assetHouseService.insertAssetHouse(assetHouse));
    }

    /**
     * 修改房屋资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:house:edit')")
    @Log(title = "房屋资产档案", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改房屋资产")
    public AjaxResult AssetHouseEdit(@Validated @RequestBody AssetHousePutVo assetHouse) {
        return toAjax(assetHouseService.updateAssetHouse(assetHouse));
    }

    /**
     * 删除房屋资产档案
     */
    @PreAuthorize("@ss.hasPermi('asset:house:remove')")
    @Log(title = "房屋资产档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{houseIds}")
    @ApiOperation(value = "删除房屋资产")
    public AjaxResult AssetHouseRemoveByIds(@NotEmpty @PathVariable String[] houseIds) {
        return toAjax(assetHouseService.deleteAssetHouseByHouseIds(houseIds));
    }
}
